 //封装密码安全级别动态检测
 var checkPssLevel = function (pass) { 
    var numberReg = /^[0-9]$/;
    var letterReg = /^[a-z]$/;
    var cLetterReg = /^[A-Z]$/;
    var specialCharacter = /^[!@#$%^&*_-]$/;
    var level = [];
    if (pass.length >= 8 && pass.length <= 10) {
        return level.push("0");
    } else {
        for (let i = 0; i <= pass.length; i++) {
            var item = pass[i];
            if (numberReg.test(item)) {
                level.push("1");
            }
            if (letterReg.test(item)) {
                level.push("2");
            }
            if (cLetterReg.test(item)) {
                level.push("3");
            }
            if (specialCharacter.test(item)) {
                level.push("4");
            }
        }	
        level = [...new Set(level)];
        //判断安全级别
        var score = 0;
        var len = level.length;
        //密码长度为8-10位或只含有数字，大小写字母，特殊字符四种情况中的2(len<=2)时为弱  
        //含三种情况为中
        //含四种情况为强
        switch (len) { 
            case 0:
                return score = 0;
            case 1:
                return score = 1;
            case 2:
                return score = 1;
            case 3:
                return score = 3;
            case 4:
                return score = 4;
        }
    }
}
//检测密码强度  input框绑定input propertychange 时间 检测值变化 执行回调事件
$('#pass').on('input propertychange',function(){ 
    console.log($(this).val())
    var level = checkPssLevel($(this).val());
    console.log("level>>", level);
    //判断level级别 设置样式
    switch (level) { 
        case 0:
            $('#weak').removeClass('weak');
            $('#secondary').removeClass('secondary');
            $('#strong').removeClass('strong');
            break;
        case 1:
            $('#weak').addClass('weak');
            $('#secondary').removeClass('secondary');
            $('#strong').removeClass('strong');                
            break;
        case 3:
            $('#secondary').addClass('secondary');
            $('#strong').removeClass('strong');                
            break;
        case 4:
            $('#strong').addClass('strong');
            break;
        default:
        $('#weak').removeClass('weak');
        $('#secondary').removeClass('secondary');
        $('#strong').removeClass('strong'); 
    }
})